package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Servlet09", value = "/denglu")
public class Servlet09 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //如果root/123123 则跳转到首页welcome.jsp , 否则，显示“登陆失败”

        if ("root".equals(username)&&"123123".equals(password)){
            //跳转（重定向）

//1
//            response.sendRedirect("welcome.jsp");
//            2
//            response.sendRedirect("user/userCenter.jsp");
//            3
            String appName=request.getContextPath();
            System.out.println(appName);
            response.sendRedirect(appName+"user/userCenter.jsp");
            //在重定向的路径在，斜杠“/”代表的含义，不是当前应用程序，而是当前服务器

        }else {
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.print("登陆失败!");
            //如果没有设置编码，默认编码是ISO-8859-1
        }







    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
